﻿using CommHelper;
using NX5WinServies;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            await gogogo();
        }

        private async Task gogogo()
        { 

            DataManager dm = new DataManager();
            DataTable dt = dm.SqlCmd("SELECT * FROM Base_Words WHERE Methods is null").table;
            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    String Msg = "我需要\"" + dr["Word"].ToString() + "\"这个单词的记忆方法，优先音节记忆和词根词缀，最少给5种记忆方法。返回格式:[{\"Mehtod\":\"方法名\",\"Model\":\"记忆模式\",\"Detail\":\"说明\"}]";
                    String Result = await AIAgent.AIBase(Msg);
                    Console.WriteLine(Result);
                    Console.WriteLine("=====================================================================");
                    dm.SqlCmd("UPDATE Base_Words SET Methods = N'" + Result.Replace("'", "''").Replace("--", "——")
                        + "' WHERE ID = " + dr["ID"].ToString());
                    this.textBox1.Text += Result
                        + Environment.NewLine + "====================================================================="
                        + Environment.NewLine;
                }
                catch
                {

                }
                //dm.Procedure("System_WordMethod", "[{\"ID\":" + dr["ID"].ToString()
                //    + ",\"Method\":\"" + Result + "\"}]");
            }
        }
    }
}
